home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / gopher / Unix / GopherTools / gopherdist.Z / gopherdist
Encoding:
Text File  |  1993-08-01  |  1.7 KB  |  85 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # This script generates a link file on standard output for a given
  4. # gopher host/port/directory.
  5. #
  6. # Example:
  7. #
  8. # gopherdist gopher.micro.umn.edu 70
  9. #
  10. # gopherdist gopher.micro.umn.edu 70 "1/UofM Campus Information"
  11.  
  12.  
  13. sub dokill {
  14.     kill 9,$child if $child;
  15. }
  16.  
  17. sub Opengopher {
  18.  
  19.     local($them,$port) = @_;    
  20.     $them = 'localhost' unless $them;
  21.  
  22.     $AF_INET = 2;
  23.     $SOCK_STREAM = 1;
  24.  
  25.     $SIG{'INT'} = 'dokill';
  26.  
  27.     $sockaddr = 'S n a4 x8';
  28.  
  29.     chop($hostname = `hostname`);
  30.  
  31.     ($name,$aliases,$proto) = getprotobyname('tcp');
  32.     ($name,$aliases,$port) = getservbyname($port,'tcp')
  33.     unless $port =~ /^\d+$/;;
  34.     ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
  35.     ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
  36.  
  37.     $this = pack($sockaddr, $AF_INET, 0, $thisaddr);
  38.     $that = pack($sockaddr, $AF_INET, $port, $thataddr);
  39.  
  40.     # Make the socket filehandle.
  41.     socket(S, $AF_INET, $SOCK_STREAM, $proto) || die $!;
  42.  
  43.     # Give the socket an address.
  44.     bind(S, $this) || die $!;
  45.  
  46.     # Call up the server.
  47.     connect(S,$that) || die $!;
  48.  
  49.     # Set socket to be command buffered.
  50.     select(S); $| = 1; select(STDOUT);
  51.  
  52. }
  53.  
  54. $Host    = shift(@ARGV) || die "Usage: $0 host port [path]";
  55. $Port    = shift(@ARGV) || die "Usage: $0 host port [path]";
  56. $Path    = shift(@ARGV);
  57.  
  58.  
  59. &Opengopher( $Host, $Port);
  60.  
  61. print S "$Path\r\n";
  62.  
  63.  
  64. while (<S>) {
  65.     chop;
  66.     chop;
  67.     if (/^\.$/) {
  68.     exit;
  69.     }
  70.  
  71.     ($ObjName, $Path, $Host, $Port) = split('\t', $_, 6);
  72.     $Name = substr($ObjName, 1);
  73.     $Obj  = substr($ObjName, 0, 1);
  74.  
  75.     print "Type=$Obj\n";
  76.     print "Name=$Name\n";
  77.     print "Path=$Path\n";
  78.     print "Host=$Host\n";
  79.     print "Port=$Port\n";
  80.     print "#\n";
  81.  
  82.  
  83. }
  84.  
  85.